package com.xjrsoft.module.customerTwo.aiplm.t_aiplm_lease_work_order.controller;

import cn.dev33.satoken.annotation.SaCheckPermission;
import cn.dev33.satoken.annotation.SaMode;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.xjrsoft.common.page.PageOutput;
import com.xjrsoft.common.page.ConventPage;
import java.util.List;
import com.xjrsoft.common.utils.DataTransUtil;
import com.xjrsoft.common.result.Response;
import com.xjrsoft.core.tool.utils.BeanUtil;
import com.xjrsoft.module.base.service.IXjrBaseCodeRuleService;
import com.xjrsoft.module.customerTwo.aiplm.t_aiplm_lease_work_order.dto.TAiplmLeaseWorkOrderDto;
import com.xjrsoft.module.customerTwo.aiplm.t_aiplm_lease_work_order.dto.SaveTAiplmLeaseWorkOrderFormDataDto;
import com.xjrsoft.module.customerTwo.aiplm.t_aiplm_lease_work_order.vo.TAiplmLeaseWorkOrderVo;
import com.xjrsoft.module.customerTwo.aiplm.t_aiplm_lease_work_order.vo.TAiplmLeaseWorkOrderListVo;
import com.xjrsoft.module.customerTwo.aiplm.t_aiplm_lease_work_order.dto.TAiplmLeaseWorkOrderListDto;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.AllArgsConstructor;

import org.springframework.web.bind.annotation.*;
import com.xjrsoft.module.customerTwo.aiplm.t_aiplm_lease_work_order.entity.TAiplmLeaseWorkOrder;
import com.xjrsoft.module.customerTwo.aiplm.t_aiplm_lease_work_order.vo.TAiplmLeaseWorkOrderVo;
import com.xjrsoft.module.customerTwo.aiplm.t_aiplm_lease_work_order.service.ITAiplmLeaseWorkOrderService;

/**
 *  控制器
 *
 * @author dongxinhang
 * @since 2024-07-03
 */
@RestController
@AllArgsConstructor
@RequestMapping("/t_aiplm_lease_work_order")
@Api(value = "法人租赁工单", tags = "法人租赁工单接口")
public class TAiplmLeaseWorkOrderController {


	private final ITAiplmLeaseWorkOrderService tAiplmLeaseWorkOrderService;

	private final IXjrBaseCodeRuleService codeRuleService;

	/**
	 * 详情 
	 */
	@GetMapping("/{id}")
	@ApiOperation(value = "详情", notes = "传入tAiplmLeaseWorkOrder")
	@SaCheckPermission(value = {"t_aiplm_lease_work_order:view", "t_aiplm_lease_work_order:modify"}, mode = SaMode.OR)
	public Response<TAiplmLeaseWorkOrderVo> getFormData(@PathVariable String id) {
		// 主表数据
		TAiplmLeaseWorkOrder tAiplmLeaseWorkOrder = tAiplmLeaseWorkOrderService.getById(id);
		TAiplmLeaseWorkOrderVo tAiplmLeaseWorkOrderVo = BeanUtil.copy(tAiplmLeaseWorkOrder, TAiplmLeaseWorkOrderVo.class);
		return Response.ok(tAiplmLeaseWorkOrderVo);
	}

	/**
	 * 自定义分页 
	 */
	@GetMapping
	@ApiOperation(value = "分页", notes = "传入tAiplmLeaseWorkOrder")
		public Response<PageOutput<TAiplmLeaseWorkOrderListVo>> getPageList(TAiplmLeaseWorkOrderListDto listDto) {
		IPage<TAiplmLeaseWorkOrder> page = tAiplmLeaseWorkOrderService.getPageList(listDto);
		List<TAiplmLeaseWorkOrderListVo> records = BeanUtil.copyList(page.getRecords(), TAiplmLeaseWorkOrderListVo.class);
			// 转换列表数据
		DataTransUtil.transListShowData(records);
		return Response.ok(ConventPage.getPageOutput(page.getTotal(), records));
	}

	/**
	 * 新增 
	 */
	@PostMapping
	@ApiOperation(value = "新增", notes = "传入tAiplmLeaseWorkOrder")
	@SaCheckPermission("t_aiplm_lease_work_order:add")
	public Response save(@RequestBody SaveTAiplmLeaseWorkOrderFormDataDto formDto) {
		TAiplmLeaseWorkOrderDto tAiplmLeaseWorkOrderDto = formDto.getTAiplmLeaseWorkOrderDto();
		TAiplmLeaseWorkOrder tAiplmLeaseWorkOrder = BeanUtil.copy(tAiplmLeaseWorkOrderDto, TAiplmLeaseWorkOrder.class);
		boolean isSuccess = tAiplmLeaseWorkOrderService.addTAiplmLeaseWorkOrder(tAiplmLeaseWorkOrder);
		if (isSuccess) {
			codeRuleService.useEncode("LeaseWorkOrder");
		}
		return Response.status(isSuccess);
	}

	/**
	 * 修改 
	 */
	@PutMapping("/{id}")
	@ApiOperation(value = "修改", notes = "传入tAiplmLeaseWorkOrder")
	@SaCheckPermission("t_aiplm_lease_work_order:modify")
	public Response update(@PathVariable String id, @RequestBody SaveTAiplmLeaseWorkOrderFormDataDto formDto) {
		TAiplmLeaseWorkOrderDto tAiplmLeaseWorkOrderDto = formDto.getTAiplmLeaseWorkOrderDto();
		TAiplmLeaseWorkOrder tAiplmLeaseWorkOrder = BeanUtil.copy(tAiplmLeaseWorkOrderDto, TAiplmLeaseWorkOrder.class);
		return Response.status(tAiplmLeaseWorkOrderService.updateTAiplmLeaseWorkOrder(id, tAiplmLeaseWorkOrder));
	}



	/**
	 * 删除 
	 */
	@DeleteMapping("/{ids}")
	@ApiOperation(value = "删除", notes = "传入ids")
	@SaCheckPermission(value = {"t_aiplm_lease_work_order:batchDelete", "t_aiplm_lease_work_order:delete"}, mode = SaMode.OR)
	public Response remove(@ApiParam(value = "主键集合", required = true) @PathVariable String ids) {
		return Response.status(tAiplmLeaseWorkOrderService.delete(ids));
	}


}
